package com.chaoxing.service.impl;

import com.chaoxing.entity.Notebook;
import com.chaoxing.entity.User;
import com.chaoxing.mapper.NotebookMapper;
import com.chaoxing.service.NotebookService;
import com.chaoxing.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@Service
@Slf4j
public class NotebookServiceImpl implements NotebookService {

    @Resource
    private NotebookMapper notebookMapper;

    @Override
    public int insertSelective(Notebook record, HttpServletRequest request) {
        HttpSession session = request.getSession(false);
        record.setCreattime(DateUtils.getTime());
        User user = (User) session.getAttribute("User");
        record.setAuthor(user.getName());
        return notebookMapper.insertSelective(record);
    }

    @Override
    public List<Notebook> selectNoteByAuthor(String author) {
        return notebookMapper.selectNoteByAuthor(author);
    }
}
